package d3_Math;

public class MathTest {
    public static void main(String[] args) {
        //目标: 了解一下Math类提供的常见方法
        //1、public static int abs(int a): 取绝对值(拿到的结果一定能格式正数)
        //  、public static int abs(int a)
        System.out.println(Math.abs(-12));//12
        System.out.println(Math.abs(123));//123
        System.out.println(Math.abs(-3.14));//3.14

        //2、public static double ceil(double a): 向上取整
        System.out.println(Math.ceil(4.00001));//5.0
        System.out.println(Math.ceil(4.0));//4.0

        //3、public static double floor(double a): 向下取整
        System.out.println(Math.floor(3.4999));//3.0
        System.out.println(Math.floor(3.6999));//3.0

        // 4、public static long round(double a): 四舍五入
        System.out.println(Math.round(3.49999));//3
        System.out.println(Math.round(3.59999));//4


        //5、public static int max(int a, int b): 取较大值
        //  public static int min(int a, int b): 取较小值
        System.out.println(Math.max(10, 20));
        System.out.println(Math.min(10, 20));

        //6、public static double pow(double a, double b): 取次方
        System.out.println(Math.pow(2, 3));// 2的3次方 8.0
        System.out.println(Math.pow(3, 2));// 3的2次方 9.0

        //7、public static double random(): 取随机数 [0.0 , 1.0) (包前部包后)
        System.out.println(Math.random());
    }
}
